package team2;

import java.util.ArrayList;
import java.util.List;

/**
 * IRManager is a class that holds all the documents.
 * It is in charge of returning query results and clustering documents.
 * Its use is to speak to the UI.
 * @author Brett Hlavinka
 */
public class IRManager
{
    private List<Document> documents;

    /**
     * The default constructor for IRManager
     * @param documents The documents that the manager is to handle.
     */
    public IRManager(List<Document> documents)
    {
        this.documents = documents;
    }

    /**
     * Method that allows something to query the manager's documents.
     * @param query The query that is checked against the documents.
     * @return The list of QueryResults that corresponds to this query.
     */
    public List<QueryResult> query(String query)
    {
        List<QueryResult> results = new ArrayList<QueryResult>();
        Vector queryVector = new Vector(query);
        for (Document document : documents)
        {
            String preview = findBestPreview(queryVector, document);
            double similarity = queryVector.similarityWith(document.getVector());
            results.add(new QueryResult(document, preview, similarity));
        }
        return results;
    }

    /**
     * Private method that finds the best preview of a document.
     * @param queryVector The query vector.
     * @param document The document to find the preview of.
     * @return The best matching preview.
     */
    private String findBestPreview(Vector queryVector, Document document)
    {
        //TODO: Increment through document's fullText and find small previews. Return the preview that has the highest similarity.
        return "";
    }
}
